import { app, BrowserWindow } from 'electron';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const createWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600
  });

  // win.loadFile('index.html')

  // 下面的url为自己启动vite项目的url。
  // win.loadURL('http://127.0.0.1:80/');
  if (app.isPackaged) {
    win.loadFile(path.join(__dirname, '../index.html'));
  } else {
    win.loadURL('http://127.0.0.1:80/');
    // 打开electron的开发者工具
    win.webContents.openDevTools({ mode: 'detach' });
  }
};

app.whenReady().then(() => {
  createWindow();
  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

